package tools;

import java.io.*;

public class BasicTools {
    public static String readFromFile(File file) throws IOException {
        StringBuilder sb = new StringBuilder();
        try (FileReader fileIn = new FileReader(file)) {
            for (int c = fileIn.read(); c != -1; c = fileIn.read()) {
                sb.append((char) c);
            }
        }
        return sb.toString();
    }

    public static void WriteToFile(File file, String str) throws IOException {
        try (FileWriter fw = new FileWriter(file)) {
            fw.write(str);
            fw.flush();
        }
    }

    public static String removeSuffix(String fileName) {
        return fileName.substring(0, fileName.lastIndexOf("."));
    }

    public static File replaceFileSuffix(File file, String suffix) {
        String fileName = file.getName();
        return new File(fileName.substring(0, fileName.lastIndexOf(".")) + suffix);
    }

    private BasicTools() {
        throw new IllegalStateException("Utility class");
    }
}
